﻿using System;
using System.Text;
using System.Collections.Generic;
using SrBBSPro.Entities;
using SrBBSPro.BaseClasses;

namespace SrBBSPro.Services
{
    public class ScheduleService : BaseService<Schedule, long>
    {

        public List<Schedule> GetScheduleList(long sid, string kind, string person,  out int count, int page)
        {
            var sql = new StringBuilder();
            sql.Append("select * from Project where id = @0 ");
            if (string.IsNullOrEmpty(kind))
            {
                sql.AppendFormat(" and kind ='{0}' " ,kind);
            }
            if (string.IsNullOrEmpty(person))
            {
                sql.AppendFormat(" and personId='{0}'" , person);
            }
            var li = DbBase.Fetch<Schedule>(sql.ToString(), sid);
            return GetLimitList(li, out count, page);
        }

        public void AddScheduleList(long sid)
        {
            var pages = DbBase.Query<PageInfo>().Where(p => p.Id == sid).ToList();
            if (pages.Count > 0)
            {
                var li = new List<Schedule>();
                var tasks = new List<string>()
                {
                    "代码开发",
                    "代码审查",
                    "单体式样书做成",
                    "单体式样书审查",
                };
                foreach(var item in pages)
                {
                    var sch = new Schedule()
                    {
                        ProjectId = sid,
                        Kind =item.Kind,
                        Info =item.PageName,
                        Tasks =""

                    };
                    li.Add(sch);
                }
                DbBase.InsertBatch(li);
            }
        }
    }
}